import { mergeRsbuildConfig, getBaseConfig, extendConfig, type RsbuildConfig } from "rsbuild-pipe";
// import { pluginSourceBuild } from "@rsbuild/plugin-source-build";
// const path = require("path");

// const xYafDir = path.resolve(__dirname, '../x-yaf');
// const xLibsDir = path.resolve(__dirname, '../x-libs');

/**
 * 生成rsbuild配置
 */
const mkRsbuildConfig = () => mergeRsbuildConfig(
  getBaseConfig({
    rsbuildConfig: {
      // 1. 入口配置
      source: {
        alias: {
          // 'x-packages/': '../x-packages/',
        },
        define: {
          // 'process.env': process.env,
        },
        // include:[
        //   {
        //     and: [xYafDir, { not: /[\\/]node_modules[\\/]/ }]
        //   },
        //   {
        //     and: [xLibsDir, { not: /[\\/]node_modules[\\/]/ }]
        //   }
        // ],
      },
      dev: {
        progressBar: true,
      },
      server: {
        port: 3001
      },
      output: {
        assetPrefix: process.env.assetPrefix ?? "",
      },
    },

    // 禁用ts类型检查
    pluginTypeCheckEnable: false,

    // 用于 monorepo 场景，支持引用其他子目录的源代码，并完成构建和热更新
    pluginSourceBuildEnable: true,
    pluginSourceBuildOptions:{
      sourceField: "x-source",
    }
  }),
  getTailwindConfig(),
  extendConfig.getBabelConfig({styledJsxEnabled: false}),
  extendConfig.getNodePolyfillConfig({
    nodePolyfillOptions:{
      globals:{
        // @ts-ignore
        stream: false
      }
    }
  })
);

/**
 * 获取tailwindcss配置
 */
const getTailwindConfig = (): RsbuildConfig => {
  return {
    tools: {
      postcss: (opts, { addPlugins }) => {
        // 配置Tailwindcss
        addPlugins(require("tailwindcss"))
      },
    },
  }
}


export default mkRsbuildConfig();



